package com.example.helper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * @author twy12138
 * @description: 分页查询控制器层
 */
@SuppressWarnings("all")
public abstract class AbstractPageController<T, E> {

  @Autowired PageService<E> pageService;
  private Class<T> dtoClass;

  public AbstractPageController() {
    ParameterizedType type = (ParameterizedType) getClass().getGenericSuperclass();
    Type[] actualTypeArguments = type.getActualTypeArguments();
    dtoClass = (Class<T>) actualTypeArguments[0];
  }

  @PostMapping("/pageQuery")
  public IPage<T> pageQuery(@RequestBody Object param) {
    IPage page = pageService.pageQuery(param);
    return PageUtils.copy(page, dtoClass);
  }
}
